package Algorithm.math;

import Common.Constant.C;
import Common.Utils.UTFactory;
import org.junit.Test;

import static Common.Utils.Tools.strTools;

/**
 * @author 蔚蔚樱
 * @version V1.0
 * @date 2022/11/21 13:07
 * @author—Email micromicrohard@outlook.com
 * @blogURL https://blog.csdn.net/Micro_Micro_Hard
 * @description 最大公约数
 * Tips:辗转相除法
 * @blogURL
 */
public class GreatestCommonDivisor {

    @Test // 验证功能：从数据库获取测试数据，用于单元测试
    public void TestFunc() throws Exception {
        UTFactory.FullTest(this.getClass());
    }

    @Test // 调试功能 : 用于复现错误的测试案例
    public void DoubleTrack() throws Exception {
        String input = "EmptyExpr  ############  NullExpr";
        String output = "EmptyExpr";
        UTFactory.DebugTest(this.getClass(), input, output);
    }

    public int Method(int a, int b) {
        if (a < 0 || b < 0) {
            return C.ErrorNum;
        }
        if (a == 0 || b == 0) {
            return a == 0 ? b : a;
        }
        if (a < b) {
            int temp = a;
            a = b;
            b = temp;
        }
        return Method(b, a % b);
    }
}
